//原生js封装的文档加载事件
document.ready(function () {


    //表单验证
    // 声明
    let password = document.querySelector('.password')
    let Text = document.querySelector('.Text')
    let hint = document.querySelector('.hint')
    let btn = document.querySelector('.btn')

    //点击btn验证
    btn.addEventListener('click', function () {
        //判断

        if (!(/^1[3-9]\d{9}$/.test(Text.value))) {
            hint.textContent = '手机号输入错误，请稍后重试'
        } else if (!password.value) {
            hint.textContent = '请输入密码'
        } else {

            //ajax发送请求
            $http.post('/users/login', { account: Text.value, password: password.value }, function (res) {
                //判断
                if (res.status === 0) {
                    alert('登入成功')

                    location.href = "../page/home.html"
                } else {
                    alert('登入失败')
                }

                //都正确    
                hint.textContent = ''

            })
        }
    })

    password.addEventListener('keyup', function (e) {
        if (e.keyCode === 13) {
            if (!(/^1[3-9]\d{9}$/.test(Text.value))) {
                hint.textContent = '手机号输入错误，请稍后重试'
            } else if (!password.value) {
                hint.textContent = '请输入密码'
            } else {
                //ajax发送请求
                $http.post('/users/login', { account: Text.value, password: password.value }, function (res) {
                    //判断
                    if (res.status === 0) {
                        alert('登入成功')

                        location.href = "../page/home.html"
                    } else {
                        alert('登入失败')
                    }

                    //都正确    
                    hint.textContent = ''
                })
            }
        }
    })

})